/**
 * Copyright (c) 2015-2019, Golly Hu 胡高 (3722711@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.hg.jfsa.web.theme;

import java.util.List;

import com.jfinal.kit.StrKit;

/**
 * @author Golly
 */
public class ThemeErrorRender extends ThemeRender {

	private int errorCode;

	public ThemeErrorRender (int errorCode, String view, List<String> excludeViewPostfixList) {
		super(view, excludeViewPostfixList);
		this.errorCode = errorCode;
	}

	public int getErrorCode () { return this.errorCode; }

	@Override
	public void render () {

		if (this.isThemePath()) {
			// 否则就是Theme链接
			Theme theme = ThemeManager.me().getCurrentTheme();
			String errorView = theme.getErrorViewMap().get(this.errorCode);

			if (StrKit.notBlank(errorView)) { // 如果Error页面已经在主题配置文件中
				this.view = errorView;
			} else if (StrKit.notBlank(theme.getErrorViewMap().get(0))) { // 如果主题配置文件中设置了通用Error页面
				this.view = theme.getErrorViewMap().get(0);
			}

		}

		super.render();
	}

}
